<?php

namespace Btr\DurakBundle\Durak;

class Cards implements \Countable
{
	/**
	 * All cards the game needs
	 * @var array
	 */
	private $cards;
	
	/**
	 * One card which represents the master suit
	 * @var unknown
	 */
	private $masterSuit;
	
	public function __construct()
	{
		$this->cards = array();
		foreach ( Suit::getSuits() as $suit)
		  for( $i = 6; $i <= 0x0E; $i++)
		{
			$this->cards[] = $suit | $i;
		}
		shuffle($this->cards);
		$this->masterSuit = $this->cards[0];
	}
	
	public function count()
	{
		return count($this->cards);
	}
	
	/**
	 * Get cards from deck.
	 * @param number $num
	 * @return array
	 */
	public function removeCards($num = 1)
	{
		$result = array_splice($this->cards, -$num);
		return $result;
	}
	
	/**
	 *  Is there any cards the player can take ?
	 *  @return boolean 
	 */
	public function isEmpty()
	{
		return empty($this->cards);
	}
	
	/**
	 *
	 * @return the array
	 */
	public function getCards() {
		return $this->cards;
	}
	
	/**
	 *
	 * @param array $cards        	
	 */
	public function setCards(array $cards) {
		$this->cards = $cards;
		return $this;
	}
	
	/**
	 *
	 * @return the integer
	 */
	public function getMasterSuit() {
		return $this->masterSuit;
	}
	
	/**
	 *
	 * @param integer $masterSuit        	
	 */
	public function setMasterSuit($masterSuit) {
		$this->masterSuit = $masterSuit;
		return $this;
	}
	
}
